/**
 *  model1
 *  Author: thuanvd_2
 *  Description: test grid, agent deplace in grid
 */

model model1

global {
	file shape_file_grid <- file('../includes/grid1.shp');
	file shape_file_block <- file('../includes/block.shp');
	file shape_file_bounds <- file('../includes/bounds.shp');
	int nb_people <- 50;
	graph the_graph;
	float min_speed <- 10.0;
	float max_speed <- 100.0; 
	
	init {
		create grid from: shape_file_grid;
		set the_graph <- as_edge_graph(list(grid));
		create block from: shape_file_block;
		create people number: nb_people {
//			set speed <- min_speed + rnd (max_speed - min_speed) ;
			set speed <- min_speed;
			set location <- any_location_in (one_of (block));
			set the_target <- any_location_in (one_of(block));
		} 
	}
}

environment bounds: shape_file_bounds;

entities {
	species grid {
		rgb color <-rgb('blue');
		aspect base{
			draw geometry: shape color: color;
		}
	}
	
	species block {
		rgb color <- rgb('red');
		aspect base{
			draw geometry: shape color: color;
		}
	}
	
	species people skills:[moving]{
		rgb color <- rgb('yellow');
		point the_target <- nil;
		aspect base{
			draw shape: circle color: color size:10;
		}
		
		reflex move when: the_target !=nil{
			do goto target: the_target on: the_graph;
			switch the_target {
				match location {set the_target <- nil;}
			}
		}
	}
}

experiment model1 type: gui {
	/** Insert here the definition of the input and output of the model */
	output {
		display grid_display refresh_every: 1{
			species block aspect: base;
			species grid aspect: base;
			species people aspect: base;
		}
	}
}
